#ifndef _ENTITY_H_
#define _ENTITY_H_

#include "Scriptable.h"
#include <fastsig/fastsig.hpp>

class Map;
class Layer;

class Entity:public Scriptable, public fastsig::trackable
{
friend class Map;
friend class Layer;
public:
	enum EntityType
	{
		UNKNOWN,
		ANIMATED,
		STATIC,
		TEXT,
		TILE
	}type;
	
	enum ConnectionType
	{
		GENERAL,
		UPDATE,
		ANIMATE,
		COUNT
	};

	Entity(EntityType type);
	void init();
	virtual ~Entity();
	Entity* clone() const;
	void remove();

	EntityType getType() const {return type;}
	
	sf::Vector2f getPosition() const;
	void setPosition(sf::Vector2f& pos);
	float getX() const;
	float getY() const;
	void setX(float x);
	void setY(float y);
	sf::Vector2f getCenter() const;
	void setCenter(sf::Vector2f& pos);
	bool getVisible() const;
	void setVisible(bool val);
	float getRotation() const;
	void setRotation(float rotation);

	virtual void update();
	
	void gotoMap(Map* map);
	Map* getCurrentMap() const {return currentMap;}
	void switchLayer(Layer* layer);
	const SQChar* getCurrentLayerName() const;
	
	sf::Drawable* getShape() const {return shape;}
	bool getDebug() const {return debug;}
	void setDebug(bool value) {debug=value;}

	virtual void serialize(SquirrelObject& out) const;
	virtual void deserialize(SquirrelObject& in);
	virtual void updateBoundingBox();
protected:
	bool debug;
	std::map<ConnectionType,fastsig::connection> connections;
	sf::Vector2f size;
	Map* currentMap;
	Layer* currentLayer;
	sf::Drawable* shape;
	bool visible;
	mutable SquirrelObject _update,_serialize,_deserialize;
};

#endif